# -*- ecoding: utf-8 -*-
# @Author: Wick
# @Time: 2024-02-24 21:41

class Gun:
    def __init__(self, model):
        # 枪的型号
        self.model = model
        # 子弹数量
        self.bullet_count = 0

    def add_bullet(self, count):
        self.bullet_count += count

    def shoot(self):
        # 判断是否还有子弹
        if self.bullet_count == 0:
            print("没有子弹")
            return
        else:
            self.bullet_count -= 1
        print(f'开火，剩余子弹{self.bullet_count}')


class Soldier:
    def __init__(self, name):
        # 1. 姓名
        self.name = name
        # 2. 枪 - 新兵没有枪
        self.gun:Gun = None

    def fire(self):
        # 1. 判断士兵是否有枪
        # if self.gun == None:
        if self.gun is None:  #用的比较多
            print("[%s] 还没有枪..." % self.name)
            return
        # 2. 高喊口号
        print("冲啊...[%s]" % self.name)
        # 3. 让枪装填子弹
        self.gun.add_bullet(50)
        # 4. 让枪发射子弹
        self.gun.shoot()


ak47 = Gun("ak")
xusanduo = Soldier("许三多")
xusanduo.gun = ak47
xusanduo.fire()

